package cemp.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class KpiCalUtil {

    public static BigDecimal calPriceIncrease(BigDecimal priceToday , BigDecimal priceLastDay){
        if(priceToday == null || priceLastDay == null || priceToday.equals(BigDecimal.ZERO) || priceLastDay.equals(BigDecimal.ZERO)){
            return null;
        }else{
            return (priceToday.min(priceLastDay)).divide(priceLastDay,2, RoundingMode.HALF_UP);
        }
    }


    public static BigDecimal calIncrease(BigDecimal o1 , BigDecimal o2){
        if(o1 == null || o2 == null || o1.equals(BigDecimal.ZERO) || o2.equals(BigDecimal.ZERO)){
            return null;
        }else{
            return o1.min(o2);
        }
    }

    public static BigDecimal calRatio(BigDecimal o1 , BigDecimal o2){
        if(o1 == null || o2 == null || o1.equals(BigDecimal.ZERO) || o2.equals(BigDecimal.ZERO)){
            return null;
        }else{
            return (o1.min(o2)).divide(o2,2, RoundingMode.HALF_UP);
        }
    }

}
